#!/bin/sh

# Slackware build script for Audacity 

# Written by Chess Griffin <chess at chessgriffin dot com>
# Thanks to Eric Hameleers for adding the audacity.desktop 
# file and other tweaks and bug fixes.

# Modified by the SlackBuilds.org project

PRGNAM=audacity		
VERSION=1.3.2	
ARCH=${ARCH:-i486}
BUILD=${BUILD:-1}
TAG=${TAG:-_SBo}
CWD=$(pwd)
TMP=${TMP:-/tmp/SBo}	
PKG=$TMP/package-$PRGNAM
OUTPUT=${OUTPUT:-/tmp}

if [ "$ARCH" = "i486" ]; then
  SLKCFLAGS="-O2 -march=i486 -mtune=i686"
elif [ "$ARCH" = "i686" ]; then
  SLKCFLAGS="-O2 -march=i686 -mtune=i686"
fi

rm -rf $PKG
mkdir -p $TMP $PKG $OUTPUT
cd $TMP || exit 1
rm -rf $PRGNAM-$VERSION
tar -xzvf $CWD/$PRGNAM-src-$VERSION.tar.gz || exit 1
cd $PRGNAM-src-$VERSION-beta || exit 1
chown -R root:root .
chmod -R u+w,go+r-w,a-s .

CFLAGS="$SLKCFLAGS" \
CXXFLAGS="$SLKCFLAGS" \
./configure \
  --prefix=/usr \
  --enable-unicode \
  --with-vorbis=system \
  --with-libmad=system \
  --with-flac=system \
  --with-libsndfile=system \
  --with-id3tag=system \
  --with-libresample=local \
  --without-soundtouch \
  || exit 1

make || exit 1
make install DESTDIR=$PKG || exit 1

( cd $PKG
  find . | xargs file | grep "executable" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null
  find . | xargs file | grep "shared object" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null
)

# We're going to overwrite the include audacity.desktop file with ours,
# and the icon isn't added at all by upstream, so we'll do that here
install -D -m 0644 $CWD/audacity.desktop $PKG/usr/share/applications/audacity.desktop
install -D -m 0644 images/AudacityLogo48x48.xpm $PKG/usr/share/pixmaps/audacity.xpm

# Move manpage directory to proper loacation; pages are gzipped already
mv $PKG/usr/share/man $PKG/usr

mkdir -p $PKG/usr/doc/$PRGNAM-$VERSION
mv $PKG/usr/share/doc/audacity/* $PKG/usr/doc/$PRGNAM-$VERSION
rm -r $PKG/usr/share/doc
cat $CWD/$PRGNAM.SlackBuild > $PKG/usr/doc/$PRGNAM-$VERSION/$PRGNAM.SlackBuild

mkdir -p $PKG/usr/share/locale/
mv $TMP/$PRGNAM-src-$VERSION-beta/locale/* $PKG/usr/share/locale/

mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc
cat $CWD/doinst.sh > $PKG/install/doinst.sh

cd $PKG
/sbin/makepkg -l y -c n $OUTPUT/$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.tgz
